<?php
Globals::requireController('Admin');
Globals::requireTable('Vipuser');
Globals::requireTable('Vmoneyimg');
Globals::requireTable('Vmoneyproduct');
Globals::requireTable('Vmoneyorder');

class VmoneyController extends AdminController
{
    protected $vipuserTable;
    protected $vmoneyimgTable;
    protected $vmoneyproductTable;
    protected $vmoneyorderTable;
    
	public function __construct($config = null)
	{
		parent::__construct($config, true);
		$this->vipuserTable = new VipuserTable($config);
		$this->vmoneyimgTable = new VmoneyimgTable($config);
		$this->vmoneyproductTable = new VmoneyproductTable($config);
		$this->vmoneyorderTable = new VmoneyorderTable($config);
	}
	
	public function indexAction()
	{
	    
	}
	
	public function adlistAction()
	{
	    $where = "1 = 1";
	    $count = $this->vmoneyimgTable->listCount($where);
	    $pageSize = 20;
	    $pageId	= $this->getIntParam('page');
	    $this->view->paging = $this->getPaging($count, $pageSize,$pageId);
	    $this->view->data = $this->vmoneyimgTable->listPage($where, 'id ASC', $pageSize, $pageId);
	}
	
	public function addetailAction()
	{
	    $id = $this->getIntParam('id');
	    if($id > 0){
	        $title = $this->vmoneyimgTable->getRow($id);
	        if($title['id'] > 0){
	            $this->view->data = $title;
	        }
	    }
	}
	
	public function doaddetailAction()
	{
	    $id = $this->getIntParam('id');
	    $data['img'] = $this->getParam('img');
	    $data['url'] = $this->getParam('url');
	    if($id > 0){
	        $this->vmoneyimgTable->update($data,$id);
	    }else{
	        $data['createdate'] = date('Y-m-d H:i:s');
	        $this->vmoneyimgTable->add($data);
	    }
	    $this->redirectToAction('adlist');
	    exit();
	}
	
	public function addeleteAction()
	{
	    $id = $this->getIntParam('id');
	    $this->vmoneyimgTable->delete($id);
	    $this->redirectToAction('adlist');
	    exit();
	}
	
	
	public function mainlistAction(){
	    $where['status'] = 1;
	    $count = $this->vmoneyproductTable->listCount($where);
	    $pageSize = 20;
	    $pageId	= $this->getIntParam('page');
	    $this->view->paging = $this->getPaging($count, $pageSize,$pageId);
	    $this->view->data = $this->vmoneyproductTable->listPage($where, 'id ASC', $pageSize, $pageId);
	}
	
	public function maindetailAction()
	{
	    $id = $this->getIntParam('id');
	    if($id > 0){
	        $title = $this->vmoneyproductTable->getRow($id);
	        if($title['id'] > 0){
	            $this->view->data = $title;
	        }
	    }
	}
	
	public function domaindetailAction()
	{
	    $id = $this->getIntParam('id');
	    $data['vmoney_count'] = $this->getParam('vmoney_count');
	    if($id > 0){
	        $this->vmoneyproductTable->update($data,$id);
	    }else{
	        $data['createdate'] = date('Y-m-d H:i:s');
	        $data['status'] = 1;
	        $this->vmoneyproductTable->add($data);
	    }
	    $this->redirectToAction('mainlist');
	    exit();
	}
	
	public function maindeleteAction()
	{
	    $id = $this->getIntParam('id');
	    $this->vmoneyproductTable->update(array('status'=>0),$id);
	    $this->redirectToAction('mainlist');
	    exit();
	}
	
	public function orderlistAction(){
	    $id = $this->getIntParam('id');
	    $data = $this->vmoneyorderTable->listAll(array('trysee_id'=>$id));
	    $this->view->data = $data;
	}
	
}
